﻿@{
    ViewBag.Title = L("Ribbon_FileStorages");
}

@model UserFolder

<div class="lineinput">
    <div id="grid"></div>
</div>
<script type="text/x-kendo-template" id="template">
    <div style="text-align:right;">
        <button type="button" onclick="ajaxParent();" class="k-button k-button-icontext" style="float:left;"><span class="k-icon k-i-folder-up"></span>@LRaw("FileStorages_MoveParent")</button>
        <button type="button" onclick="grid.data().addRow();" class="k-button k-button-icontext"><span class="k-icon k-i-folder-add"></span>@LRaw("FileStorages_NewFolder")</button>
        <button type="button" onclick="ajaxDel($('input[name=GroupID]').checkedVal())" class="k-button k-button-icontext"><span class="k-icon k-delete"></span>@LRaw("Ribbon_DeleteGroup")</button>
    </div>
</script>
<script type="text/javascript">
    var folderID = @Model.FolderID;
    var parentID = @Model.ParentID;
    $(document).ready(function () {
        $('#grid').grid({
            transport: {
                read: {
                    url: '@Url.Action("QueryStorages")',
                    dataType: "json",
                    type: "POST",
                    data: {
                        folderID: function () {
                            return folderID;
                        }
                    }
                }
            },
            schema: {
                model: {
                    id: "ID",
                    fields: {
                        ID: { editable: false, nullable: true },
                        FolderID: { type: "number", editable: true, validation: { required: true} },
                        Name: { editable: true, validation: { required: true} },
                        Ext: { editable: false },
                        CreateDate: { editable: false },
                        LastUpdateDate: { editable: false },
                        Size: { editable: false },
                        IsFolder: { type: 'boolean', editable: false },
                        Url: { editable: false }
                    }
                }
            },
            columns: [
                { title: 'chkall', template: '<input type="checkbox" value="#= ID #" name="ID"/>', width: "28px" },
                {
                    field:'Name',  title: '@LRaw("FileStorages_Name")', template: '#if(IsFolder){# <span class="k-sprite folder"></span> #= Name # #}else{# <a href="javascript:void(0);" onclick="showFile(this);"><span class="k-sprite" style="background:url(@Cores.GetUtil("resources/icons")/#= Ext #.gif);"></span> #= Name #</a> #}#\
                  <div class="actionpanel">\
                    <a onclick="hashgo(\'?groupid=#= ID #\');" title="@LRaw("PageGroup_Create")" href="javascript:void(0);"><span class="k-icon k-i-restore"></span> @LRaw("PageGroup_Create") </a>\
                    <a onclick="grid.data().editRow($(this).closest(\'tr\'));" title="@LRaw("Edit")" href="javascript:void(0);"><span class="k-icon k-edit"></span> @LRaw("Edit") </a> \
                    <a onclick="ajaxDel(#= ID #);" title="@LRaw("Delete")" href="javascript:void(0);"><span class="k-icon k-delete"></span> @LRaw("Delete") </a>\
                    <a class="moz-move-up" onclick="ajaxSort(#= ID #, false);" title="@LRaw("MoveUp")" href="javascript:void(0);"><span class="k-icon k-i-arrow-n"></span> @LRaw("MoveUp") </a>\
                    <a class="moz-move-down" onclick="ajaxSort(#= ID #, true);" title="@LRaw("MoveDown")" href="javascript:void(0);"><span class="k-icon k-i-arrow-s"></span> @LRaw("MoveDown") </a>\
                  </div>', 
                  editor: function(container, options) {
                        $('<input class="k-textbox" name="' + options.field + '"/>\
                    <div class="actionpanel">\
                        <a onclick="grid.data().saveRow();" title="@LRaw("FileStorages_Update")" href="javascript:void(0);"><span class="k-icon k-i-tick"></span> @LRaw("FileStorages_Update") </a>\
                        <a onclick="grid.data().cancelRow();" title="@LRaw("FileStorages_Cancel")" href="javascript:void(0);"><span class="k-icon k-i-cancel"></span> @LRaw("FileStorages_Cancel") </a> \
                    </div>').appendTo(container);
                  }
                },
                { template: '#= CreateDate #', title: '@LRaw("CreateDate")' },
                { template: '#= LastUpdateDate #', title: '@LRaw("LastUpdateDate")' },
                { template: '#= Size #', title: '@LRaw("FileStorages_Size")' }
            ],
            toolbar: '#template',
            checkall: 'ID',
            gridin: {
                dataBound: function () {
                    $('a.moz-move-up:first').remove();
                    $('a.moz-move-down:last').remove();
                },
                sortable: false
            }
        });
    });

    function ajaxDel(ids){
        if(!ids) {
            alert('@LRaw("Action_SelectedFirst", L("Action_PageGroup"))');
            return;
        }
        ajaxDelete('@Url.Action("DeletePageGroups")',
        {
            ids:function(){
                return ids;
            },
            cultureName: function () {
                return cultureName;
            }
        }, 
        function(data){
            grid.refresh();
        }, 
        '@LRaw("Action_DeletedPageGroupConfirm")');
    }

    function ajaxSort(id, isDown) {
        ajaxUdSort('@Url.Action("SortPageGroup")', {
            cultureName: function () { return cultureName; }
        }, id, isDown, function (data) {
            grid.refresh();
        });
    }
    //返回父文件夹
    function ajaxParent(){
        folderID = parentID;
        grid.refresh();
    }
</script>

@section head{
    @Html.Using("~/app_utilities/resources/resource.css")    
}